//
//  RGMainPageNavView.m
//  RedGrass
//
//  Created by wukong on 2018/11/27.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGMainPageNavView.h"
#import "RGMainpageSearchVIew.h"

@interface RGMainPageNavView()

@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UIButton *contactBtn;
@property (strong, nonatomic) UIButton *searchBtn;
@property (strong, nonatomic) RGMainpageSearchVIew *searchView;



@end

@implementation RGMainPageNavView

-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.searchBtn];
        [self addSubview:self.titleLabel];
        [self addSubview:self.contactBtn];
        [self addSubview:self.searchView];
        [self addMasonry];
    }
    return self;
}

-(void) addMasonry{
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self).mas_offset(CGPointZero);
    }];
    
    [_searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self).mas_offset(0);
        make.left.mas_equalTo(self).mas_offset(20);
    }];
    
    [_contactBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self).mas_offset(0);
        make.right.mas_equalTo(self).mas_offset(-20);
    }];
    CGSize size = self.searchView.viewSize;
    [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(size);
        make.centerY.mas_equalTo(self.searchBtn.mas_centerY).mas_offset(0);
        make.left.mas_equalTo(self.searchBtn.mas_left).mas_offset(0);
    }];
}


#pragma mark - reponse
-(void)contactBtnClick:(UIButton *) button{
    if(self.navViewBtnClickBlock){
        self.navViewBtnClickBlock(kMainPageQRCodeScanTag);
    }
    
}

-(void)searchBtnClick:(UIButton *) button{
    if(self.navViewBtnClickBlock){
        self.navViewBtnClickBlock(kMainPageSearchTag);
    }
//    _searchView.alpha = 0.1;
//    _searchView.hidden = NO;
//    _searchBtn.hidden = YES;
//    [UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
//        self.searchView.alpha = 1.0;
//
//    } completion:^(BOOL finished) {
//       self.searchBtn.hidden = NO;
//    }];
}

#pragma mark - getter

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = FONT(customBoldFontName, 17);
        _titleLabel.text = @"推荐";
        _titleLabel.textColor = [UIColor whiteColor];
    }
    return _titleLabel;
}

-(UIButton *)contactBtn{
    if(!_contactBtn){
        _contactBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_contactBtn setBackgroundImage:IMAGE_NAMED(@"扫码") forState:UIControlStateNormal];
        [_contactBtn addTarget:self action:@selector(contactBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _contactBtn;
}

-(UIButton *)searchBtn{
    if(!_searchBtn){
        _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_searchBtn setBackgroundImage:IMAGE_NAMED(@"search") forState:UIControlStateNormal];
        [_searchBtn addTarget:self action:@selector(searchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _searchBtn;
}

-(RGMainpageSearchVIew *)searchView{
    if(!_searchView){
        _searchView = [[RGMainpageSearchVIew alloc]init];
        _searchView.hidden = YES;
        _searchView.alpha = 0;
    }
    return _searchView;
}




@end
